home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Examples / InputSprocketPPTest / ISpElementView.cp next >
Encoding:
Text File  |  1996-05-16  |  2.0 KB  |  100 lines  |  [TEXT/CWIE]

  1. //====
  2. // ISpElementView.cp
  3. //=====
  4.  
  5. #include "ISpElementView.h"
  6. #include "ISpTestGlobals.h"
  7. #include <TextUtils.h>
  8. #include "ISpPPTestTools.h"
  9.  
  10. ISpElementView::ISpElementView(LStream *inStream):LOffscreenView(inStream)
  11. {
  12.     StartIdling();
  13. }
  14.  
  15. ISpElementView::~ISpElementView()
  16. {
  17. }
  18.  
  19. ISpElementView *ISpElementView::CreateISpElementViewStream(LStream *inStream)
  20. {
  21.   return (new ISpElementView(inStream));
  22. }
  23.  
  24.  
  25. void ISpElementView::SpendTime(const EventRecord &inMacEvent)
  26. {
  27.     Refresh();
  28.     UpdatePort();
  29. }
  30.  
  31.  
  32. void ISpElementView::DrawSelf()
  33. {
  34.     if (gElement == nil) { return; }
  35.     
  36.     Rect r;
  37.     Str255 theString;
  38.         
  39.     CalcLocalFrameRect(r);
  40.     r.left += 10;
  41.     
  42.     EraseRect(&r);
  43.     
  44.     OSStatus pollStatus;
  45.     UInt32 state;
  46.     
  47.     pollStatus = ISpElement_GetSimpleState(gElement, &state);
  48.     ISpElementInfo info;
  49.     ISpElement_GetInfo(gElement, &info);
  50.     
  51.     MoveTo(r.left, r.top + 15);
  52.     DrawString("\pGlobal Error Code:  ");
  53.     NumToString(gStatus, theString);
  54.     DrawString(theString);
  55.  
  56.     MoveTo(r.left, r.top + 30);
  57.     DrawString("\pPoll Error Code:  ");
  58.     NumToString(pollStatus, theString);
  59.     DrawString(theString);
  60.  
  61.     MoveTo(r.left, r.top + 45);
  62.     DrawString("\pData:  ");
  63.     UInt32ToHexString(state, theString);
  64.     DrawString(theString);
  65.  
  66.     {
  67.         const rectWidth = 100;
  68.         Rect maxRect = {2,0,11,rectWidth};
  69.         Rect progRect = maxRect;
  70.         float percent = state;
  71.         percent /= 0xffffffff;
  72.         
  73.         progRect.right = rectWidth * percent;
  74.         
  75.         OffsetRect(&maxRect, r.left, r.top + 47);
  76.         OffsetRect(&progRect, r.left, r.top + 47);
  77.         
  78.         ::FrameRect(&maxRect);
  79.         ::PaintRect(&progRect);
  80.     }
  81.     
  82.     MoveTo(r.left, r.top + 75);
  83.     DrawString("\pElement Num:  ");
  84.     UInt32ToHexString((unsigned long) gElement, theString);
  85.     DrawString(theString);
  86.  
  87.     MoveTo(r.left, r.top + 90);
  88.     DrawString("\pElement Label:  ");
  89.     UInt32ToFourByte(info.theLabel, theString);
  90.     DrawString(theString);
  91.  
  92.     MoveTo(r.left, r.top + 105);
  93.     DrawString("\pElement Kind:  ");
  94.     UInt32ToFourByte(info.theKind, theString);
  95.     DrawString(theString);
  96.  
  97.     MoveTo(r.left, r.top + 120);
  98.     DrawString("\pElement Name:  ");
  99.     DrawString(info.theString);
  100. }